<?php
class Companies extends UaModel {
	var $name = "Company";
	var $common_cols = "Company.id AS ID, AS MemberID,industry_id AS CompanyIndustryId,style_id AS Style,Company.name AS CompanyName,Company.description AS Description,main_prod AS MainProduct,boss_name AS Leader,tel AS Tel,mobile AS MobilePhone,link_man AS Linker,fax AS Fax,found_date AS FoundDate,email AS CompanyEmail,Company.*";
	var $alias_cols = "CONCAT(telcode,'-',telzone,'-',tel) AS MixTel,CONCAT(faxcode,'-',faxzone,'-',fax) AS MixFax";
	
	var $manage_type = array (1 => "生产型", 2 => "贸易型", 3 => "服务型", 4 => "政府或其他机构" );
	var $main_market = array (1 => "大陆", 2 => "港澳台", 3 => "北美", 4 => "南美", 5 => "西欧", 6 => "东欧", 7 => "东亚", 8 => "东南亚", 9 => "中东", 10 => "非洲", 11 => "大洋洲", 12 => "其他市场" );
	var $company_funds = array (0 => "**不公开**", 1 => "人民币 10万元之下", 2 => "人民币 10万-30万", 3 => "人民币 30万-50万", 4 => "人民币 50万-100万", 5 => "人民币 100万-300万", 6 => "人民币 300万-500万", 7 => "人民币 500万-1000万", 8 => "人民币 1000 万元/年-5000 万元/年", 9 => "人民币 5000 万元/年-1 亿元/年", 9 => "其他" );
	var $year_annuals = array (0 => "**不公开**", 1 => "人民币 10万元之下/年", 2 => "人民币 10万-30万/年", 3 => "人民币 30万-50万/年", 4 => "人民币 50万-100万/年", 5 => "人民币 100万-300万/年", 6 => "人民币 300万-500万/年", 7 => "人民币 500万-1000万/年", 8 => "人民币 1000万-5000万/年", 9 => "人民币 5000万以上/年", 9 => "其他" );
	var $economic_type = array ("请选择", "国有企业", "集体企业", "股份合作企业", "联营企业", "国有联营企业", "集体联营企业", "国有与集体联营企业", "其他联营企业", "有限责任公司", "国有独资的有限责任公司", "其他有限责任公司", "股份有限公司", "私营企业", "私营独资企业", "私营合作企业", "私营有限责任公司", "私营股份有限公司", "个人独资企业", "与港、澳、台商合资经营企业", "与港、澳、台商合作经营企业", "港、澳、台商独资经营企业", "港、澳、台商投资股份有限公司", "中外合资经营企业", "中外合作经营企业", "外商独资企业", "外商投资股份有限公司", "非盈利组织", "其他" );
	var $company_status = array ("0" => "无效", "1" => "有效", "2" => "等待审核", "3" => "审核不通过" );
	var $employee_amount = array (0 => "**不公开**", 1 => "5 人以下", 2 => "5 - 10 人", 3 => "11 - 50 人", 4 => "51 - 100 人", 5 => "101 -500 人", 6 => "501- 1000 人", 7 => "1000 人以上" );
	var $menu = null;
	var $configs = null;
	
	function Companies() {
		//$this->setTableName($GLOBALS['tb_prefix'].$this->table_name);
	}
	
	function getCompanyInfo($companyid, $memberid = null, $cols = null) {
		$sql = "select ";
		if (empty ( $cols ))
			$sql .= $this->common_cols;
		else
			$sql .= $cols;
		$sql .= " from " . $this->getTable ( true ) . " where 1 ";
		if (! is_null ( $memberid ))
			$sql .= " and member_id=" . $memberid;
		if (! is_null ( $companyid ))
			$sql .= " and id=" . $companyid;
		$res = $GLOBALS ['g_db']->GetRow ( $sql );
		return $res;
	}
	
	function statCompany() {
		$sql = "select type_id,count(Company.id) as Amount from " . $this->getTable ( true ) . " group by Company.type_id";
		$return = $GLOBALS ['g_db']->GetAll ( $sql );
		foreach ( $return as $key => $val ) {
			$m [$val ['type_id']] = $val ['Amount'];
		}
		if ($return)
			$m ['sum'] = array_sum ( $m );
		return $m;
	}
	
	function update($posts, $action = null, $id = null, $tbname = null, $conditions = null) {
		global $data;
		if (isset ( $data ['Templet'] ['title'] )) {
			$cfg ['templet_name'] = $data ['Templet'] ['title'];
			$posts ['configs'] = serialize ( $cfg );
		}
		return $this->save ( $posts, $action, $id, $tbname, $conditions );
	}
	
	function getTempletName($configs) {
		$cfgs = unserialize ( $configs );
		return $cfgs ['templet_name'];
	}
	
	function setConfigs($configs) {
		$cfgs = unserialize ( $configs );
		$this->configs = $cfg;
	}
	
	function getConifigs() {
		return $this->configs;
	}
	
  /*
	function setMenu($pretend_level) {
		global $_GET, $config_subdomain, $subdomain_support, $userid;
		if ($subdomain_support) {
			$user_id = $userid; // From member-index.php
		} else {
			$user_id = uaAddSlashes ( $_GET ['userid'] );
		}
		$tmp_menus = array ();
		$tmp_host = uaGetHost ( false );
		if ($subdomain_support) {
			$tmp_menus ['index'] = "http://" . $user_id . $config_subdomain . "/?do=home";
			$tmp_menus ['intro'] = "http://" . $user_id . $config_subdomain . "/?do=intro";
			$tmp_menus ['product'] = "http://" . $user_id . $config_subdomain . "/?do=product";
			$tmp_menus ['trade'] = "http://" . $user_id . $config_subdomain . "/?do=trade";
			$tmp_menus ['news'] = "http://" . $user_id . $config_subdomain . "/?do=news";
			$tmp_menus ['honour'] = "http://" . $user_id . $config_subdomain . "/?do=honour";
			$tmp_menus ['hr'] = "http://" . $user_id . $config_subdomain . "/?do=hr";
			$tmp_menus ['contact'] = "http://" . $user_id . $config_subdomain . "/?do=contact";
			$tmp_menus ['feedback'] = "http://" . $user_id . $config_subdomain . "/?do=feedback";
		} else {
			$tmp_menus ['index'] = URL . "member/index.php?do=home&userid=" . $user_id;
			$tmp_menus ['intro'] = URL . "member/index.php?do=intro&userid=" . $user_id;
			$tmp_menus ['product'] = URL . "member/index.php?do=product&userid=" . $user_id;
			$tmp_menus ['trade'] = URL . "member/index.php?do=trade&userid=" . $user_id;
			$tmp_menus ['news'] = URL . "member/index.php?do=news&userid=" . $user_id;
			$tmp_menus ['honour'] = URL . "member/index.php?do=honour&userid=" . $user_id;
			$tmp_menus ['hr'] = URL . "member/index.php?do=hr&userid=" . $user_id;
			$tmp_menus ['contact'] = URL . "member/index.php?do=contact&userid=" . $user_id;
			$tmp_menus ['feedback'] = URL . "member/index.php?do=feedback&userid=" . $user_id;
		}
		$this->menu = $tmp_menus;
	}
  */

  function setMenu($pretend_level){
		global $_GET, $config_subdomain;
		$user_id = uaAddSlashes($_GET['userid']);
		$tmp_menus = array();
		$tmp_host = uaGetHost(false);
		switch ($pretend_level) {
			case 1:
				$tmp_menus['index'] = "http://".$user_id.$config_subdomain."/";
				$tmp_menus['intro'] = "http://".$user_id.$config_subdomain."/intro/";
				$tmp_menus['product'] = "http://".$user_id.$config_subdomain."/product/";
				$tmp_menus['trade'] = "http://".$user_id.$config_subdomain."/trade/";
				$tmp_menus['news'] = "http://".$user_id.$config_subdomain."/news/";
				$tmp_menus['honour'] = "http://".$user_id.$config_subdomain."/honour/";
				$tmp_menus['hr'] = "http://".$user_id.$config_subdomain."/hr/";
				$tmp_menus['contact'] = "http://".$user_id.$config_subdomain."/contact/";
				$tmp_menus['feedback'] = "http://".$user_id.$config_subdomain."/feedback/";
				break;
			default:
				$tmp_menus['index'] = URL."member/index.php?userid=".$user_id;
				$tmp_menus['intro'] = URL."member/intro.php?userid=".$user_id;
				$tmp_menus['product'] = URL."member/product.php?userid=".$user_id;
				$tmp_menus['trade'] = URL."member/trade.php?userid=".$user_id;
				$tmp_menus['news'] = URL."member/news.php?userid=".$user_id;
				$tmp_menus['honour'] = URL."member/honour.php?userid=".$user_id;
				$tmp_menus['hr'] = URL."member/hr.php?userid=".$user_id;
				$tmp_menus['contact'] = URL."member/contact.php?userid=".$user_id;
				$tmp_menus['feedback'] = URL."member/feedback.php?userid=".$user_id;
				break;
		}
		$this->menu = $tmp_menus;
	}
	
	function getMenu() {
		return $this->menu;
	}
}
?>
